# Loading the data
load("experiment_data.RData")

############
# FIGURE 3 #
############
# Treatment effects for those who are copartisans of president
# Weak treatment, compared to control
copartisans.treatment.weak <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                     experiment.data$obstruction.binary.support[which(experiment.data$copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "weak")])
# Moderate treatment, compared to control
copartisans.treatment.moderate <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                         experiment.data$obstruction.binary.support[which(experiment.data$copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "moderate")])
# Severe treatment, compared to control
copartisans.treatment.severe <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                       experiment.data$obstruction.binary.support[which(experiment.data$copartisan.president == 1 & experiment.data$obstruction.treatment.factor == "severe")])
# Effects to plot (difference of control from weak/moderate/severe), in percentage terms
copartisans.treatment.effects <- (c((copartisans.treatment.weak$estimate[2]-copartisans.treatment.weak$estimate[1]),
                                    (copartisans.treatment.moderate$estimate[2]-copartisans.treatment.moderate$estimate[1]), 
                                    (copartisans.treatment.severe$estimate[2]-copartisans.treatment.severe$estimate[1])))*100
# Confidence intervals to plot
copartisans.ci.lower <- (c(copartisans.treatment.weak$conf.int[1], copartisans.treatment.moderate$conf.int[1], copartisans.treatment.severe$conf.int[1])*-1)*100
copartisans.ci.upper <- (c(copartisans.treatment.weak$conf.int[2], copartisans.treatment.moderate$conf.int[2], copartisans.treatment.severe$conf.int[2])*-1)*100
# Average support for Senate behavior across all obstruction conditions
round(mean(experiment.data$obstruction.binary.support[which(experiment.data$copartisan.president == 1 & experiment.data$obstruction.treatment.factor %in% c("weak","moderate","strong"))])*100,1)

# Treatment effects for those who are independents
# Weak treatment, compared to control
independents.treatment.weak <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$independent.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                      experiment.data$obstruction.binary.support[which(experiment.data$independent.president == 1 & experiment.data$obstruction.treatment.factor == "weak")])
# Moderate treatment, compared to control
independents.treatment.moderate <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$independent.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                          experiment.data$obstruction.binary.support[which(experiment.data$independent.president == 1 & experiment.data$obstruction.treatment.factor == "moderate")])
# Severe treatment, compared to control
independents.treatment.severe <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$independent.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                        experiment.data$obstruction.binary.support[which(experiment.data$independent.president == 1 & experiment.data$obstruction.treatment.factor == "severe")])
# Effects to plot (difference of control from weak/moderate/severe), in percentage terms
independents.treatment.effects <- (c((independents.treatment.weak$estimate[2]-independents.treatment.weak$estimate[1]),
                                     (independents.treatment.moderate$estimate[2]-independents.treatment.moderate$estimate[1]), 
                                     (independents.treatment.severe$estimate[2]-independents.treatment.severe$estimate[1])))*100
# Confidence intervals to plot
independents.ci.lower <- (c(independents.treatment.weak$conf.int[1], independents.treatment.moderate$conf.int[1], independents.treatment.severe$conf.int[1])*-1)*100
independents.ci.upper <- (c(independents.treatment.weak$conf.int[2], independents.treatment.moderate$conf.int[2], independents.treatment.severe$conf.int[2])*-1)*100
# Average support for Senate behavior across all obstruction conditions
round(mean(experiment.data$obstruction.binary.support[which(experiment.data$independent.president == 1 & experiment.data$obstruction.treatment.factor %in% c("weak","moderate","strong"))])*100,1)

# Treatment effects for those who are outpartisans
# Weak treatment, compared to control
outpartisans.treatment.weak <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                      experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "weak")])
# Moderate treatment, compared to control
outpartisans.treatment.moderate <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                          experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "moderate")])
# Severe treatment, compared to control
outpartisans.treatment.severe <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "control")],
                                        experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "severe")])
# Effects to plot (difference of control from weak/moderate/severe), in percentage terms
outpartisans.treatment.effects <- (c((outpartisans.treatment.weak$estimate[2]-outpartisans.treatment.weak$estimate[1]),
                                     (outpartisans.treatment.moderate$estimate[2]-outpartisans.treatment.moderate$estimate[1]), 
                                     (outpartisans.treatment.severe$estimate[2]-outpartisans.treatment.severe$estimate[1])))*100
# Confidence intervals to plot
outpartisans.ci.lower <- (c(outpartisans.treatment.weak$conf.int[1], outpartisans.treatment.moderate$conf.int[1], outpartisans.treatment.severe$conf.int[1])*-1)*100
outpartisans.ci.upper <- (c(outpartisans.treatment.weak$conf.int[2], outpartisans.treatment.moderate$conf.int[2], outpartisans.treatment.severe$conf.int[2])*-1)*100
# Average support for Senate behavior across all obstruction conditions
round(mean(experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor %in% c("weak","moderate","strong"))])*100,1)

par(mar=c(4.5,5.75,1,1), mgp=c(2,.25,0))
plot(copartisans.treatment.effects,c(0.65,0.5,0.35),ylim=c(0,3),xlim=c(-60,20), tck=0, cex.main=1, main="", cex.lab=1.2, cex.axis=1, 
     pch=c(16,17,15), cex=1.5, xlab="Change in Support When Compared to Control (No Obstruction)", xaxt="n", yaxt="n", ylab="", lwd=1.5, col=c("grey60","grey40","black"))
abline(v=0, lty=2)
#lines(x=group, y=independents+jitter)
axis(1,at=seq(-60,20,by=10), cex.axis=1, 
     labels=c("-60","-50","-40","-30","-20","-10","0","10","20"), tck=0.01, las=1)
axis(2, at=c(0.4,1.4,2.4),cex.axis=0.9,labels=c("Copartisans
(Avg. Obst.
Support = 27.7)","Independents
(Avg. Obst.
Support = 38.6)","Outpartisans
                                                (Avg. Obst.
Support = 59.9)"), padj=0, las=1, tick=F)
legend("topright", c("Weak","Moderate","Severe"), col=c("grey60","grey40","black"), pch=c(16,17,15), cex=0.8)
segments(copartisans.ci.lower, c(0.65,0.5,0.35), copartisans.ci.upper, c(0.65,0.5,0.35), lwd=1, col=c("grey60","grey40","black"))
points(x=independents.treatment.effects, y=c(1.65,1.5,1.35), pch=c(16,17,15), col=c("grey60","grey40","black"), cex=1.5)
segments(independents.ci.lower, c(1.65,1.5,1.35), independents.ci.upper, c(1.65,1.5,1.35), lwd=1, col=c("grey60","grey40","black"))
points(x=outpartisans.treatment.effects, y=c(2.65,2.5,2.35), pch=c(16,17,15), col=c("grey60","grey40","black"), cex=1.5)
segments(outpartisans.ci.lower, c(2.65,2.5,2.35), outpartisans.ci.upper, c(2.65,2.5,2.35), lwd=1, col=c("grey60","grey40","black"))

# Outpartisan severe/weak difference, discussed in text
outpartisans.severe.weak <- t.test(experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "weak")],
                                   experiment.data$obstruction.binary.support[which(experiment.data$outpartisan.president == 1 & experiment.data$obstruction.treatment.factor == "severe")])
outpartisans.severe.weak$estimate[2]-outpartisans.severe.weak$estimate[1]
